/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Trainings {
    public static boolean insertTraining(Entity.Training tra){
        try {
            String sql = "insert into tblTrainings values(?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, tra.get_TrainID());
            ps.setString(2, tra.get_TrainName());
            ps.setString(3, tra.get_Information());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Trainings.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateTraining(Entity.Training tra){
        try {
            String sql = "update tblTrainings set TrainName=?, Information=? where TrainID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, tra.get_TrainName());
            ps.setString(2, tra.get_Information());
            ps.setString(3, tra.get_TrainID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Trainings.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }       
    }
    
    public static void deleteTraining(String strTrainID){
        try {
            String sql = "delete from tblTrainings where TrainID = '" + strTrainID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Trainings.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }



}
